package study;

import org.jsoup.nodes.Document;
import org.testng.Assert;
import org.testng.Reporter;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;


public class NewTest {
    long datex1, datex2;

    @DataProvider
    public Object[][] mydatasource() {
        return new Object[][]{
                {327.01}, {137.4}, {12.52}
        };
    }

    @DataProvider
    public Object[][] mydatasource1() {
        return new Object[][]{
                {327}, {137}, {12}
        };
    }

    @Test
    public void test1() {
        String expected = "news";
        String actual;
        WebService mytest = new WebService();
        actual = mytest.message1("abc");
        //断言
        Assert.assertEquals(actual, expected);
    }

    @Test
    public void test2() {
        int expected = 10;
        int actual;
        WebService mytest = new WebService();
        actual = mytest.calc(1, 9);
        //断言
        Assert.assertEquals(actual, expected);
    }

    @Test(dataProvider = "mydatasource")
    public void test3(double x) {
        double expected = 54.0;
        double actual;
        WebService mytest = new WebService();
        actual = mytest.calc(x, 137.4);
        //断言
        Assert.assertEquals(actual, expected);
    }

    @Test(invocationCount = 5000, threadPoolSize = 50)
    public void f() {
        jsoup myget = new jsoup();
        long date1 = System.currentTimeMillis();
        Document doc = myget.jsopget1("http://www.baidu.com");
        long date2 = System.currentTimeMillis();
        long diff = date2 - date1;
        System.out.println("Thread#:" + Thread.currentThread().getId() + "|" + diff);
        Reporter.log("time:" + diff);
        Assert.assertTrue(diff < 1000);
    }

    @BeforeClass
    public void beforeclass() {
        datex1 = System.currentTimeMillis();
    }

    @AfterClass
    public void afterclass() {
        datex2 = System.currentTimeMillis();
        long diff = datex2 - datex1;
        long tps = 50 / (diff/1000);
        System.out.println("Test Case | " + diff + "| Tps | " + tps);
        Reporter.log("Test Case | " + diff + "| Tps | " + tps);
    }
}
